package com.bkgy.modular.calsidata.service;

import com.bkgy.component.Consumer;
import com.bkgy.modular.calsidata.dao.TbC653PDOlistDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
//@Async
public class SaveC653PDOtoMgdb {
    @Resource
    private TbC653PDOlistDao tbC653PDOlistDao;
    @Resource
    private Consumer consumer;

    //@Scheduled(cron = "0 */4 * * * ?")
   /* public void saveSiData653() {
        try {
            log.error("SaveC653PDOtoMgdb+saveSiData653：");
            LocalDate.now();
            QueryWrapper<JColdPdo653> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("STATUS", 0);
//            queryWrapper.eq("createtime", 0);
//            queryWrapper.gt("createtime", "");
            List<JColdPdo653> jColdPdo653 = tbC653PDOlistDao.selectList(queryWrapper);
            //System.out.println(jColdPdo653);
            for (JColdPdo653 ColdPdo653 : jColdPdo653) {

//                ColdPdo653.getOUT_MAT_NO();
//                ColdPdo653.getIN_MAT_NO();

                String endtime = ColdPdo653.getPROD_END_TIME();
                //String endtime = "20230103104711";

                String endtimey = endtime.substring(0, 4);


                String endtimem = endtime.substring(4, 6);
                Integer endtimemi = Integer.parseInt(endtimem);
                String endtimed = endtime.substring(6, 8);
                Integer endtimedi = Integer.parseInt(endtimed);
                String path = "/dscdata/" + endtimey + "/" + endtimemi + "/" + endtimedi + "/";
                String C653 = "{\n" +
                        "   \"key\" : {\n" +
                        "      \"endtime\" : \"" + endtime + "\",\n" +
                        "      \"entid\" : \"" + ColdPdo653.getIN_MAT_NO() + "\",\n" +
                        "      \"extid\" : \"" + ColdPdo653.getOUT_MAT_NO() + "\",\n" +
                        "      \"path\" : \"" + path + "\"\n" +
                        "   }\n" +
                        "}";

                if (consumer.receiveTopic653(C653)) {
                    JColdPdo653 upJColdPdo653 = new JColdPdo653();
                    upJColdPdo653.setId(ColdPdo653.getId());
                    upJColdPdo653.setSTATUS(1);
                    int roucout = tbC653PDOlistDao.updateById(upJColdPdo653);
                    //System.out.println("更新行数为：roucout=" + roucout);
                } else {
                    JColdPdo653 upJColdPdo653 = new JColdPdo653();
                    upJColdPdo653.setId(ColdPdo653.getId());
                    upJColdPdo653.setSTATUS(2);
                    int roucout = tbC653PDOlistDao.updateById(upJColdPdo653);
                    //System.out.println("更新行数为：roucout=" + roucout);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/
}
